package screens;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import core.UIController;

public class MenuList extends List implements CommandListener {

	private Command commandSair;
	private static MenuList instance;

	private MenuList() {
		super("Menu", List.IMPLICIT);

		this.commandSair = new Command("Sair", Command.EXIT, 1);

		this.append("Rel. Vendas por Funcionário", null);
		this.append("Rel. Vendas por Produto", null);
		this.append("Mudar a senha", null);

		this.addCommand(commandSair);
		this.setCommandListener(this);
	}

	public static MenuList getInstance() {
		if (instance == null) {
			instance = new MenuList();
		}
		return instance;
	}

	public void commandAction(Command command, Displayable displayable) {
		try {
			if (command.equals(List.SELECT_COMMAND)) {
				if (getSelectedIndex() == 0) {
					UIController.getInstance().setCurrent(VendasFuncionarioForm.getInstance());
				} else if (getSelectedIndex() == 1) {
					UIController.getInstance().setCurrent(VendasProdutoForm.getInstance());
				} else if (getSelectedIndex() == 2) {
					UIController.getInstance().setCurrent(ChangePasswordForm.getInstance());
				}
			} else if (command.equals(commandSair)) {
				UIController.getInstance().sair();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
